$(function() {
    var width = $(window).width()
    if (width < 768) {
      var height = $(window).height()
      height = height - 50;
      $('.c .wifi-main').height(height);
      // $(".ct .tb .tbs").click(function() {
      // console.log('222')
      //   if (!$(this).find("span").hasClass("tab-active")) {
      //     var index = parseInt($(this).attr("index"));
      //       tab(index);
      //       tab2(index);
      //     $(this).find("span").addClass("tab-active")
      //   }
      //   $(this).find("span").siblings().removeClass('tab-active');
      // })
    } else {
      //   $(".ct .tb .tbs").click(function() {
      //   console.log('1111')
      //     if (!$(this).hasClass("active")) {
      //         $(this).addClass("active");
      //         var index = parseInt($(this).attr("index"));
      //         tab(index);
      //         tab2(index);
      //         var title = $(this).find("span").text();
      //         $("#child-title").text(title);
      //     }
      //     $(this).siblings().removeClass('active');
      // });
    }
    $('#menu .i').click(function() {
        var link = $(this).attr("link");
        menutab(link);
    });
    //移动端导航跳转
    $('#phone-nav .i').click(function() {
        var link = $(this).attr("link");
        menutab(link);
    });
    window.onresize = function() {
        // tidyWidthHight();
    };
    // tidyWidthHight();
    addEye();
    addEye2();
    showNav()
});

//移动端显示导航页
function showNav() {
    $('.h-nav').on('click', function () {
        $('#phone-nav').css('height', '100%');
        // $(document.body).css('overflow','hidden');
    });
    $('.nav-close').on('click', function () {
        $('#phone-nav').css('height', '0');
        // $(document.body).css('overflow','auto');
    });
    $('#phone-nav .i').on('click',function () {
        $(this).addClass('active');
    })
    $('.h-app').on('click',function () {
        console.log(11111);
        $('.h-right .d').css('display') === 'none' ? $('.h-right .d').css('display','block') : $('.h-right .d').css('display','none');
    })
    $('.container').on('click',function () {
        $('.h-right .d').css('display','none');
    })

}

function addEye() {
    var html = "<img class='eye-open' show='1' onclick='showpwd(this)' src='/luci-static/resources/imgs/eye-close.png'>";
    $('.cd input[type=password]').parent().append(html);
}

function addEye2() {
    var html = "<img class='eye-open' show='1' onclick='showpwd(this)' src='/luci-static/resources/imgs/eye-close.png'>";
    $('.shrink-content input[type=password]').parent().append(html);
}


function showpwd(obj) {
    if ($(obj).attr('show') == '1') {
        $(obj).attr('src', '/luci-static/resources/imgs/eye-open.png');
        $(obj).parent().find('input[type=password]').attr('type', "text");
        $(obj).attr('show', '0');
        $(obj).attr('class', 'eye-close');
    } else {
        $(obj).attr('src', '/luci-static/resources/imgs/eye-close.png');
        $(obj).parent().find('input[type=text]').attr('type', "password");
        $(obj).attr('show', '1');
        $(obj).attr('class', 'eye-open');
    }
}

function tidyWidthHight() {
    var width = window.innerWidth;
    var height = window.innerHeight;
    var hheight = $("#head").height();
    var menuwidth = $("#menu").width();
    if (width <= 1280) {
        $(".container").css("height", height - hheight - 2);
        $(".content").css("height", height - hheight - 2);
        $(".content .c .ct").css("min-height", height - hheight - 130);
    } else {
        $(".container").css("height", height - hheight - 25);
        $(".content").css("height", height - hheight - 25);
        $(".content .c .ct").css("min-height", height - hheight - 200);
    }
}

function menutab(link) {
    window.location.href = link;
    $('#phone-nav').css('height', '0')
}

function tab(index) {
    var page = $(".ct .ci").eq(index);
    $(page).siblings().removeClass('show')
    $(page).addClass("show");
}

function tab2(index) {
  var page = $(".ct .tab").eq(index);
  $(page).siblings().removeClass('show')
  $(page).addClass("show");
}


function logout(obj) {
    var url = $(obj).attr("url");
    $.post(url, function(data) {
        window.location.href = "/cgi-bin/luci/";
    })
}

var utils = {};
utils.getDateDiff = function(dateTimeStamp) {
    var result = moment(dateTimeStamp * 1000).format('HH:mm:ss');
    return result
};
utils.checkIsMac = function(mac) {
    var bValidate = RegExp("^[A-F0-9]{2}(:[A-F0-9]{2}){5}$").test(mac);
    if (!bValidate) {
        bValidate = RegExp("^[A-F0-9]{2}(-[A-F0-9]{2}){5}$").test(mac);
    }
    return bValidate;
};
utils.checkIsIp = function(ip) {
    var bValidate = RegExp("^((\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5]|[*])\\.){3}(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5]|[*])$").test(ip);
    return bValidate;
};
utils.alert = function(msg) {
    layer.alert(msg, {
        title: "提示信息",
        time: 0,
        closeBtn: 0
    });
};
utils.confirmdo = function(msg, fn) {
    layer.confirm(msg, {
        time: 0,
        title: "提示信息",
        btn: ["确定", "取消"],
        closeBtn: false,
        yes: function() {
            layer.closeAll();
            fn();
        },
        no: function() {
            layer.closeAll();
        }
    })
};
utils.loading = function(time, html) {
    layer.open({
        type: 1,
        area: ['400px', '200px'],
        title: false,
        closeBtn: false,
        shade: 0.6,
        time: time,
        content: html
    });
};

utils.loadingWithheight = function(time, height, html, fn) {
    layer.open({
        type: 1,
        area: ['400px', height],
        title: false,
        closeBtn: false,
        shade: 0.6,
        time: time,
        content: html
    });
};

utils.formatSeconds = function(value) {
    var theTime = parseInt(value); // 秒  
    var theTime1 = 0; // 分  
    var theTime2 = 0; // 小时  
    if (theTime > 60) {
        theTime1 = parseInt(theTime / 60);
        theTime = parseInt(theTime % 60);
        if (theTime1 > 60) {
            theTime2 = parseInt(theTime1 / 60);
            theTime1 = parseInt(theTime1 % 60);
        }
    }
    var result = "" + parseInt(theTime) + "秒";
    if (theTime1 > 0) {
        result = "" + parseInt(theTime1) + "分" + result;
    }
    if (theTime2 > 0) {
        result = "" + parseInt(theTime2) + "小时" + result;
    }
    return result;
};

utils.limitRefrush = function() {
    $(document).bind("keydown", function(e) {
        e = window.event || e;
        if (e.keyCode == 116) {
            e.keyCode = 0;
            return false;
        }
    });
}
utils.unlimitRefrush = function() {
    $(document).unbind("keydown", function(e) {
        e = window.event || e;
        if (e.keyCode == 116) {
            e.keyCode = 0;
            return true;
        }
    });
};

utils.formateLimitSpeed = function(speed) {
    var limitSpeed = 0;
    if (speed >= 1024) {
        limitSpeed = Math.round((speed / 1024) * 100) / 100 + "Mb/S";
    } else {
        limitSpeed = Math.round(speed * 100) / 100 + "Kb/S";
    }
    return limitSpeed;
};

utils.formateSpeed = function(srcSpeed) {
    var targetSpeed = 0;
    if (srcSpeed / 1024 >= 1024) {
        targetSpeed = Math.round((srcSpeed / 1024 / 1024) * 100) / 100 + "Mb/S";
    } else {
        targetSpeed = Math.round((srcSpeed / 1024) * 100) / 100 + "Kb/S";
    }
    return targetSpeed;
};

